package com.wuseguang.springcloud.dao.jdbc;

import com.wuseguang.springcloud.JdbcTemplate.BaseTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

@Repository
public class StudentFacesTwoJdbc extends BaseTemplate {

    private Logger logger = LoggerFactory.getLogger(this.getClass());


    public Integer insertClassStudentFaces(Integer id, Integer schoolId) {
        logger.info("添加学生班级人脸数据");
        String sql = "INSERT INTO   student_faces_registration(student_faces_id,deviceid,state,school_id) " +
                "select ?, b.deviceid,1,? from classes c left join classroom cr on (cr.classid=c.id) " +
                "left join bancard b on (b.classroomid=cr.id)  where c.school_id = ? and b.id is not null";
        return dao.update(sql,id,schoolId,schoolId);
    }

    public Integer updateClassStuentFaces(String studentId) {
        logger.info("删除学生班级人脸数据");
        String sql = "UPDATE `student_faces_registration` SET `state` = 3 WHERE `student_faces_id` in (select id from student_faces_two where student_id in ("+studentId+")) and state = 2";
        return dao.update(sql);
    }


    public Boolean judgeStudentFaces(Integer id){
        logger.info("判断学生人脸是否已删除完整");
        logger.info("添加学生班级人脸数据");
        String sql = "select count(1) `count` from student_faces_registration where state != 1 and student_faces_id = ?";
        Integer count = queryCount(sql,id);
        //大于0表示还有人脸
        if(count>0){
            return true;
        }
        return false;
    }
}
